<template>
  <div id="app">
    <nav>
      <router-link to="/">首页</router-link> |
      <router-link to="/public-activities">公开活动列表</router-link> |
      <router-link v-if="isAuthenticated && userRole === 'admin'" to="/activity-management">活动管理</router-link> |
      <a v-if="isAuthenticated" href="#" @click.prevent="logout">退出登录</a>
      <router-link v-else to="/login">登录</router-link>
    </nav>
    <router-view />
  </div>
</template>

<script>
export default {
  computed: {
    isAuthenticated() {
      return !!localStorage.getItem('userRole');
    },
    userRole() {
      return localStorage.getItem('userRole');
    },
  },
  methods: {
    logout() {
      localStorage.removeItem('userRole');
      if (this.$route.path !== '/') {
        this.$router.push('/');
      }
    },
  },
  watch: {
    $route(to, from) {
      // 当路由变化时，重新加载页面
      window.location.reload();
    }
  }
};
</script>

<style>
/* ... existing code ... */
</style>